using System.Collections.Generic;
using UnityEngine;

public class ShowTime : MonoBehaviour
{
	public Transform m_transform;

	public Transform body;

	public Transform CamPoint;

	public Transform leftblank;

	public Transform rightblank;

	public Transform leftempennage;

	public Transform rightempennage;

	public GameObject leftjet;

	public GameObject rightjet;

	private float rotationx;

	private float rotationz;

	public float speed;

	private float rightleftsoft;

	private float rightleftsoftabs;

	public float rotation_base_x;

	public float rotation_base_y;

	public float body_rotation_z;

	private float divesalto;

	private float diveblocker;

	public Transform lookpoint;

	public float Xval;

	public float Yval;

	public List<Vector3> waypos;

	private Vector3 tempdir;

	public Vector3 curTargetPos;

	private float curangleZ;

	private float curangleX;

	public int curpoint;

	private float maxangleZ = 30f;

	public GameObject speedsmoke;

	private float empennage_curangle;

	private float empennage_angle = 15f;

	private float flank_curangle_left;

	private float flank_curangle_right;

	private float flank_angle = 15f;

	private void Start()
	{
		if (GlobalInf.graphicMemory < 100)
		{
			UnityVersionUtil.SetActiveRecursive(speedsmoke, state: false);
		}
	}

	public void init_info(int curp, Transform camp)
	{
		CamPoint = camp;
		curpoint = (curp + 1) % 6;
		curTargetPos = waypos[curpoint];
		m_transform.position = waypos[curp];
		m_transform.forward = waypos[curpoint] - waypos[curp];
		camp.transform.parent = lookpoint;
		if (GlobalInf.CurrentQuality < Quality.Low)
		{
			UnityVersionUtil.SetActiveRecursive(leftjet, state: false);
			if (rightjet != null)
			{
				UnityVersionUtil.SetActiveRecursive(rightjet, state: false);
			}
		}
	}

	private void Update()
	{
		movetotarget();
		CamPoint.localPosition = Vector3.Lerp(CamPoint.localPosition, Vector3.zero, Time.deltaTime * 5f);
		rotate_empennage();
		rotate_flank();
	}

	public void movetotarget()
	{
		m_transform.Translate(0f, 0f, speed * Time.deltaTime);
		tempdir = m_transform.InverseTransformPoint(curTargetPos);
		m_transform.rotation = Quaternion.Slerp(m_transform.rotation, Quaternion.LookRotation(curTargetPos - m_transform.position), Time.deltaTime * 0.5f);
		Vector3 localEulerAngles = body.localEulerAngles;
		curangleZ = localEulerAngles.z;
		if (Mathf.Abs(tempdir.x) > 50f)
		{
			curangleZ = Mathf.LerpAngle(curangleZ, (0f - tempdir.x) / Mathf.Abs(tempdir.x) * maxangleZ, Time.deltaTime * 1f);
		}
		else
		{
			curangleZ = Mathf.LerpAngle(curangleZ, (0f - tempdir.x) / 50f * maxangleZ, Time.deltaTime * 1f);
		}
		body.localRotation = Quaternion.Euler(0f, 0f, curangleZ);
		if (curangleZ < 180f)
		{
			Xval = (0f - curangleZ) / 30f;
		}
		else
		{
			Xval = (360f - curangleZ) / 30f;
		}
		if (Vector3.Distance(m_transform.position, waypos[curpoint]) <= speed)
		{
			curpoint = (curpoint + 1) % waypos.Count;
			curTargetPos = waypos[curpoint];
		}
	}

	public void movefun()
	{
		m_transform.Translate(0f, 0f, speed * Time.deltaTime);
		Vector3 eulerAngles = m_transform.eulerAngles;
		rotationx = eulerAngles.x;
		Vector3 localEulerAngles = body.localEulerAngles;
		rotationz = localEulerAngles.z;
		if (Yval <= 0f)
		{
			m_transform.Rotate(Yval * Time.deltaTime * rotation_base_x, 0f, 0f);
		}
		if (Yval > 0f)
		{
			m_transform.Rotate((0.8f - divesalto) * Yval * Time.deltaTime * rotation_base_x, 0f, 0f);
		}
		m_transform.Rotate(0f, Time.deltaTime * rotation_base_y * Xval, 0f, Space.World);
		body.transform.Rotate(0f, 0f, Time.deltaTime * body_rotation_z * (1f - rightleftsoftabs - diveblocker) * Xval * -1f, Space.Self);
		if (Xval <= 0f && rotationz > 0f && rotationz < 90f)
		{
			rightleftsoft = rotationz * 2.2f / 100f * -1f;
		}
		if (Xval >= 0f && rotationz > 270f)
		{
			rightleftsoft = 7.92f - rotationz * 2.2f / 100f;
		}
		if (rightleftsoft > 1f)
		{
			rightleftsoft = 1f;
		}
		if (rightleftsoft < -1f)
		{
			rightleftsoft = -1f;
		}
		if ((double)rightleftsoft > -0.01 && (double)rightleftsoft < 0.01)
		{
			rightleftsoft = 0f;
		}
		rightleftsoftabs = Mathf.Abs(rightleftsoft);
		if (rotationx < 90f)
		{
			divesalto = rotationx / 100f;
		}
		if (rotationx > 90f)
		{
			divesalto = -0.2f;
		}
		if (rotationx < 90f)
		{
			diveblocker = rotationx / 200f;
		}
		else
		{
			diveblocker = 0f;
		}
		if (rotationz < 180f && Xval > 0f)
		{
			body.transform.Rotate(0f, 0f, rightleftsoft * Time.deltaTime * body_rotation_z, Space.Self);
		}
		if (rotationz > 180f && Xval < 0f)
		{
			body.transform.Rotate(0f, 0f, rightleftsoft * Time.deltaTime * body_rotation_z, Space.Self);
		}
		if (!Input.GetButton("Horizontal"))
		{
			if (rotationz < 135f)
			{
				body.transform.Rotate(0f, 0f, rightleftsoftabs * Time.deltaTime * (0f - body_rotation_z), Space.Self);
			}
			if (rotationz > 225f)
			{
				body.transform.Rotate(0f, 0f, rightleftsoftabs * Time.deltaTime * body_rotation_z, Space.Self);
			}
		}
	}

	public void rotate_flank()
	{
		if (leftblank == null)
		{
			return;
		}
		if (Mathf.Abs(Xval) >= 0.5f)
		{
			Vector3 localEulerAngles = leftblank.localEulerAngles;
			flank_curangle_left = Mathf.LerpAngle(localEulerAngles.x, (0f - Xval) * flank_angle, Time.deltaTime * 4f);
			if (rightblank != null)
			{
				Vector3 localEulerAngles2 = rightblank.localEulerAngles;
				flank_curangle_right = Mathf.LerpAngle(localEulerAngles2.x, Xval * flank_angle, Time.deltaTime * 4f);
			}
		}
		else
		{
			Vector3 localEulerAngles3 = leftblank.localEulerAngles;
			flank_curangle_left = Mathf.LerpAngle(localEulerAngles3.x, 0f, Time.deltaTime * 2f);
			if (rightblank != null)
			{
				Vector3 localEulerAngles4 = rightblank.localEulerAngles;
				flank_curangle_right = Mathf.LerpAngle(localEulerAngles4.x, 0f, Time.deltaTime * 2f);
			}
		}
		Transform transform = leftblank;
		float x = flank_curangle_left;
		Vector3 localEulerAngles5 = leftblank.localEulerAngles;
		float y = localEulerAngles5.y;
		Vector3 localEulerAngles6 = leftblank.localEulerAngles;
		transform.localRotation = Quaternion.Euler(x, y, localEulerAngles6.z);
		if (rightblank != null)
		{
			Transform transform2 = rightblank;
			float x2 = flank_curangle_right;
			Vector3 localEulerAngles7 = rightblank.localEulerAngles;
			float y2 = localEulerAngles7.y;
			Vector3 localEulerAngles8 = rightblank.localEulerAngles;
			transform2.localRotation = Quaternion.Euler(x2, y2, localEulerAngles8.z);
		}
	}

	public void rotate_empennage()
	{
		if (!(leftempennage == null))
		{
			if (Mathf.Abs(Yval) >= 0.5f)
			{
				Vector3 localEulerAngles = leftempennage.localEulerAngles;
				empennage_curangle = Mathf.LerpAngle(localEulerAngles.x, (0f - Yval) * empennage_angle, Time.deltaTime * 4f);
			}
			else
			{
				Vector3 localEulerAngles2 = leftempennage.localEulerAngles;
				empennage_curangle = Mathf.LerpAngle(localEulerAngles2.x, 0f, Time.deltaTime * 2f);
			}
			leftempennage.localRotation = Quaternion.Euler(empennage_curangle, 0f, 0f);
			rightempennage.localRotation = Quaternion.Euler(empennage_curangle, 0f, 0f);
		}
	}
}
